from pprint import pprint
from interface.MemberInterface import MemberInterface
from utils.SendMethod import SendMethod


class OrderInterface:
    def __init__(self, url):
        self.url = url

    # 确认订单
    def confirm_order(self, login_payload, payload):
        # 获取token
        token = MemberInterface(self.url).get_member_token(login_payload)
        # 发送确认订单请求,获得响应数据
        url = self.url + '/order/generateConfirmOrder'
        return SendMethod.send_method('post', url=url, headers=token, json=payload)

    # 生成订单
    def build_order(self, login_payload, payload):
        # 获取token
        token = MemberInterface(self.url).get_member_token(login_payload)
        # 发送生成订单请求,获得响应数据
        url = self.url + '/order/generateOrder'
        return SendMethod.send_method('post', url=url, headers=token, json=payload)

    # 支付成功回调
    def pay_success(self, login_payload, payload):
        # 获取token
        token = MemberInterface(self.url).get_member_token(login_payload)
        # 发送请求,获得响应数据
        url = self.url + '/order/paySuccess'
        return SendMethod.send_method('post', url=url, headers=token, data=payload)


if __name__ == '__main__':
    url = 'http://47.108.206.100:8085'
    login_payload = {
        'username': 'yyn1234',
        'password': '12345678'
    }
    payload = [2738]
    pprint(OrderInterface(url).confirm_order(login_payload=login_payload, payload=payload))
    payload = {
        "cartIds": [2738],
        "memberReceiveAddressId": 2407,
        "payType": 2,
    }
    pprint(OrderInterface(url).build_order(login_payload=login_payload, payload=payload))
    payload = {
        'orderId': 3392,
        'payType': 2
    }
    print(OrderInterface(url).pay_success(login_payload=login_payload, payload=payload))
